<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>加盟回收</title>
		<link rel="stylesheet" href="<c:url value="/static/ldx/css/style.css"/>" />
		<script type="text/javascript" src="<c:url value="/static/ldx/js/lib/rem750.js"/>"></script>
	</head>
<body class="bf">
	<div id="wrap">
		<div class="wrap_joined">
			<h1 class="title">绿大侠加盟在线申请</h1>
			<div id="wrap_select_all">
				<div class="wrap_select">
					<div class="wrap_category common_list" title="goods">
						<div class="common relative">
							<div>
								<label>1. 选择加盟类别 </label>
							</div>
							<ul class="ul_common_list ul_goods clearfix">
								<li data="回收员">回收员</li>
								<li data="打包站">打包站</li>
							</ul>
						</div>
					</div>
					<div class="common_list mt20">
						<div class="common  relative">
							<div>
								<label> 2. 您的姓名 </label>
							</div>
							<input type="text" class="input_text text_name mt20"></input>
						</div>
					</div>
					<div class="common_list mt20">
						<div class="common  relative">
							<div>
								<label> 3. 您的联系方式 </label>
							</div>
							<input type="text" class="input_text text_phone mt20"
								onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
								onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}"
								maxlength="11"></input>
						</div>
					</div>

					<div class="wrap_category common_list mt20" title="category">
						<div class="common  relative">
							<div>
								<label>4. 选择经营品类</label>
							</div>
							<ul class="ul_common_list ul_category clearfix">
								<li id="废纸类">废纸类</li>
								<li id="废塑料类">废塑料类</li>
								<li id="废金属类">废金属类</li>
								<li id="废钢铁">废钢铁</li>
								<li id="废衣服">废衣服</li>
							</ul>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="wrap_btn mt100 mb100">
			<a href="javascript:void(0)" class="button" id="submit_btn">提交</a>
		</div>

		<!--下单成功提示弹窗开始-->
		<div class="mask mask_joined">
			<div class="msg-succ">
				<img src="<c:url value="/static/ldx/img/succ_icon.png"/>" />
				<div class="f20">提交成功</div>
				<p class="mt10">客服人员会在1个工作日内联系您</p>
				<a href="<c:url value="/wx/toLdxHome.do"/>">知道了</a>
			</div>
		</div>
		<!--下单成功提示弹窗结束-->
	</div>
	<script type="text/javascript" src="<c:url value="/static/ldx/js/lib/jquery-3.3.1.min.js"/>"></script>
	<script type="text/javascript">
                var title_;
                var text_;
                var data_name;
                var id_;
                $(document).ready(function() {
                    //回收类别支持多选事件
                    $(".ul_category").on("click", "li", function() {
                        $(this).toggleClass("on");
                    })
                    //加盟类别单选事件
                    $(".ul_goods").on("click", "li", function() {
                        $(this).addClass("on").siblings("li").removeClass("on");
                    })
                    
                    $("#submit_btn").on("click", function() {
                        //加盟类别
                        var text_goods;//1回收员  2打包站
                        //姓名
                        var text_name = $(".text_name").val();
                        //电话
                        var text_phone = $(".text_phone").val();
                        var regMobile = /^1\d{10}$/;
                        //经营品类
                        var text_category = [];
                        var bool = true;
                        if($(".ul_goods li").is(".on")) {
                            var text_goods = $(".ul_goods li.on").attr("data");
                        } else {
                            alert("加盟类别必选");
                            bool = false;
                            return;
                        }
                        if(!text_name) {
                            alert("姓名不能为空");
                            bool = false;
                            return;
                        }
                        if(!text_phone) {
                            alert("电话不能为空");
                            bool = false;
                            return;
                        } else if(!regMobile.test(text_phone)) {
                            alert("请填入有效电话号码");
                            bool = false;
                            return;
                        }
                        if($(".ul_category li").is(".on")) {
                            $(".ul_category li.on").each(function() {
                                var str_ = $(this).attr("id");
                                text_category.push(str_);
                            })
                            console.log(text_category);
                        } else {
                            alert("经营类别必选");
                            bool = false;
                            return;
                        }
                        if(bool == true) {
                            var f = arguments.callee,self = this;
                            $(self).unbind('click', f);
                            $.ajax({
                                type: "POST",
                                url: "<c:url value="/wx/saveJoin.do"/>",
                                async: true,
                                data: {
                                	joinName : text_goods,
                                	name : text_name,
                                	telephone : text_phone,
                                	businessTypeStr : text_category,
                                	status : 1,
                                },
                                success: function(data) {
                                    if(data.msg == "1") {
                                        $(".mask").show();
                                    } else {
                                        $(self).click(f);
                                    }
                                }
                            });
                        }
                    })
                })
            </script>
</body>
</html>